package com.song.user.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.song.user.entity.RoleApi;
import com.song.user.service.RoleApiService;
import com.song.common.result.ResultEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.ObjectUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.Serializable;
/**
* <p>
    * 角色菜单关联信息 控制器
    * </p>
*
* @author song
* @since 2024-06-05
*/
@Api(tags = {"角色菜单关联信息 控制器"})
@RestController
@RequestMapping("/role_api")
public class RoleApiController {

    @Autowired
    RoleApiService roleApiService;

    /**
    * 分页查询数据
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "按条件分页检索角色菜单关联信息",notes = "按条件分页检索角色菜单关联信息")
    @GetMapping(value = "/pageList")
    public ResultEntity<Page<RoleApi>> pageList(
        @Validated RoleApi roleApi,
        @ApiParam(value = "页码", defaultValue = "1")
        @RequestParam(defaultValue = "1") int pageNum,
        @ApiParam(value = "分页大小", defaultValue = "10")
        @RequestParam(defaultValue = "10") int pageSize
    ) {
        Page<RoleApi> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<RoleApi> lambda = new QueryWrapper<RoleApi>().lambda();
        if(ObjectUtils.isNotEmpty(roleApi.getRoleId())){
            lambda.eq(RoleApi::getRoleId,roleApi.getRoleId());
        }
        if(ObjectUtils.isNotEmpty(roleApi.getApiId())){
            lambda.eq(RoleApi::getApiId,roleApi.getApiId());
        }
        return ResultEntity.success(roleApiService.page(page,lambda));
    }

    /**
    * 查询数据List
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "查询全部角色菜单关联信息",notes = "查询全部角色菜单关联信息")
    @GetMapping(value = "/list")
    public ResultEntity<List<RoleApi>> list() {
        List<RoleApi> roleApiList = roleApiService.list();
        return ResultEntity.success(roleApiList);
    }

    /**
    * 角色菜单关联信息新增
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "新增角色菜单关联信息",notes = "新增角色菜单关联信息")
    @PostMapping(value = "/add")
    public ResultEntity add(@RequestBody RoleApi roleApi) {
        roleApiService.save(roleApi);
        return ResultEntity.success();
    }

    /**
    * 角色菜单关联信息修改
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "修改角色菜单关联信息",notes = "修改角色菜单关联信息")
    @PostMapping(value = "/update")
    public ResultEntity edit(@RequestBody RoleApi roleApi) {
        roleApiService.updateById(roleApi);
        return ResultEntity.success();
    }

    /**
    * 删除角色菜单关联信息
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "按id删除角色菜单关联信息",notes = "按id删除角色菜单关联信息")
    @PostMapping(value = "/delete")
    public ResultEntity delete(@RequestParam Serializable id) {
        roleApiService.removeById(id);
        return ResultEntity.success();
    }


    /**
    * 根据id查询角色菜单关联信息
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "根据id查询角色菜单关联信息",notes = "根据id查询修改角色菜单关联信息")
    @GetMapping(value = "/detail")
    public ResultEntity<RoleApi> detail(@RequestParam Serializable id) {
        RoleApi roleApi = roleApiService.getById(id);
        return ResultEntity.success(roleApi);
    }
}